﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Manager_System
{
    public partial class main_form : Form
    {
        public main_form()
        {
            InitializeComponent();
        }

        private void main_form_Load(object sender, EventArgs e)
        {
            Refresh_order_LV();
            Refresh_warehouse_material_LV();
            Refresh_warehouse_product_LV();
            Refresh_material_species_LV();
            Refresh_plain_LV();
            Refresh_ingot_LV();
            Refresh_ingot_process_LV("n");
            Refresh_Quality_LV();
            Refresh_black_process_LV("n");
            Refresh_white_process_LV("n");
        }
        #region 第一页
        public void Refresh_order_LV()
        {
            this.main_order_listView.Clear();
            #region 初始化，建立main_order_listView

            main_order_listView.Columns.Clear();
            main_order_listView.Columns.Add("ID", 0, HorizontalAlignment.Left);

            main_order_listView.Columns.Add("签订时间", 85, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("最后期限", 85, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("开始时间", 85, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("完成时间", 85, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("材质", 110, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("规格", 110, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("元/吨", 60, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("重量/吨", 70, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("定金/元", 70, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("订单状态", 75, HorizontalAlignment.Left);
            main_order_listView.Columns.Add("总价/元", 80, HorizontalAlignment.Left);



            string sql = "select * from T_order";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);


            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["Sign_time"].ToString().Substring(0, 9));
                li.SubItems.Add(reader["Request_time"].ToString().Substring(0, 9));
                if (reader["Start_time"].ToString().Equals("NULL") || reader["Start_time"].ToString().Equals(""))
                {
                    li.SubItems.Add("没确定");

                }
                else
                {

                    li.SubItems.Add(reader["Start_time"].ToString().Substring(0, 9));
                }
                if (reader["End_time"].ToString().Equals("NULL") || reader["End_time"].ToString().Equals(""))
                {
                    li.SubItems.Add("没确定");
                }
                else
                {
                    li.SubItems.Add(reader["End_time"].ToString().Substring(0, 9));
                }
                li.SubItems.Add(reader["Material"].ToString());
                li.SubItems.Add(reader["Specification"].ToString());
                li.SubItems.Add(reader["Price"].ToString());

                li.SubItems.Add(reader["Weight"].ToString());


                li.SubItems.Add(reader["Front_money"].ToString());


                li.SubItems.Add(reader["Status"].ToString());

                li.SubItems.Add(reader["Sum"].ToString());
                main_order_listView.Items.Add(li);
            }
            db.close();
            #endregion
        }

        private void select_combobox_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region 控制查询的条件
            if (this.select_combobox.SelectedIndex == 0)
            {
                this.value_panel.Visible = true;
                this.between_panel.Visible = false;
                this.query_button.Visible = true;
            }
            if (this.select_combobox.SelectedIndex == 1)
            {
                this.value_panel.Visible = false;
                this.between_panel.Visible = true;
                this.query_button.Visible = true;
            }
            #endregion
        }

 

        private void attribute_combobox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.select_combobox.SelectedIndex = 1;
            this.select_combobox.Visible = true;
            if (this.attribute_combobox.SelectedIndex >= 7 && this.attribute_combobox.SelectedIndex <= 9)
            {
                this.select_combobox.SelectedIndex = 0;
                this.select_combobox.Enabled = false;
            }
        }

        private void query_button_Click(object sender, EventArgs e)
        {
            //清空结果面板
            this.main_order_listView.Items.Clear();
            this.select_combobox.Enabled = true;
            string sql="";
            //首先恢复全部不可见
            this.query_button.Visible = false;
            this.select_combobox.Visible = false;
            this.value_panel.Visible = false;
            this.between_panel.Visible = false;
            //然后判断是什么属性
            int index = Convert.ToInt32(attribute_combobox.SelectedIndex.ToString());
            string attribute = "";
            switch (index)
            {
                case 0: attribute = "Sum";
                    break;
                case 1: attribute = "Sign_time";
                    break;
                case 2: attribute = "Request_time";
                    break;
                case 3: attribute = "Start_time";
                    break;
                case 4: attribute = "End_time";
                    break;
                case 5: attribute = "Weight";
                    break;
                case 6: attribute = "Front_money";
                    break;
                case 7: attribute = "Status";
                    break;
                case 8: attribute = "Material";
                    break;
                case 9: attribute = "Specification";
                    break;
                case 10: attribute = "Price";
                    break;
            }

            //再然后判断是介于还是等于,0是等于,1是介于
            if (this.select_combobox.SelectedIndex == 0)
            {
                sql = "select * from T_order where "+attribute+" = '"+value_textbox.Text.Trim()+"'";
            }
            else if (this.select_combobox.SelectedIndex == 1)
            {
                sql = "select * from T_order where " + attribute +  " >= '" + between_low_textbox.Text.Trim() + "' and " + attribute + " <= '" + between_high_textbox.Text.Trim() + "'";
            }
            //最后执行查询
            DBhelp db = new DBhelp();
            SqlDataReader reader =db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["Sign_time"].ToString().Substring(0, 9));
                li.SubItems.Add(reader["Request_time"].ToString().Substring(0, 9));
                if (reader["Start_time"].ToString().Equals("NULL") || reader["Start_time"].ToString().Equals(""))
                {
                    li.SubItems.Add("没确定");

                }
                else
                {

                    li.SubItems.Add(reader["Start_time"].ToString().Substring(0, 9));
                }
                if (reader["End_time"].ToString().Equals("NULL") || reader["End_time"].ToString().Equals(""))
                {
                    li.SubItems.Add("没确定");
                }
                else
                {
                    li.SubItems.Add(reader["End_time"].ToString().Substring(0, 9));
                }
                li.SubItems.Add(reader["Material"].ToString());
                //应该增加这个材质的id
                li.SubItems.Add(reader["Specification"].ToString());
                li.SubItems.Add(reader["Price"].ToString());

                li.SubItems.Add(reader["Weight"].ToString());


                li.SubItems.Add(reader["Front_money"].ToString());
                string s = "";
                string status = reader["Status"].ToString();
                if (status.Equals("1"))
                {
                    s = "未开始";
                }
                else if (status.Equals("2"))
                {
                    s = "正生产";
                }
                else if (status.Equals("3"))
                {
                    s = "已完工";
                }
                li.SubItems.Add(s.ToString());

                li.SubItems.Add(reader["Sum"].ToString());
                main_order_listView.Items.Add(li);
            }
            db.close();

        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            #region 修改按钮（右键菜单）
            string id = this.main_order_listView.FocusedItem.SubItems[0].Text;
            string sum = this.main_order_listView.FocusedItem.SubItems[11].Text;
            string sign_time = this.main_order_listView.FocusedItem.SubItems[1].Text;
            string request_time = this.main_order_listView.FocusedItem.SubItems[2].Text;
            string start_time = this.main_order_listView.FocusedItem.SubItems[3].Text;
            string end_time = this.main_order_listView.FocusedItem.SubItems[4].Text;
            string weight = this.main_order_listView.FocusedItem.SubItems[8].Text;
            string front_money = this.main_order_listView.FocusedItem.SubItems[9].Text;
            string status = this.main_order_listView.FocusedItem.SubItems[10].Text;
            string material = this.main_order_listView.FocusedItem.SubItems[5].Text;
            string specification = this.main_order_listView.FocusedItem.SubItems[6].Text;
            string price = this.main_order_listView.FocusedItem.SubItems[7].Text;
            order_modify modify = new order_modify(id, sum, sign_time, request_time, weight, front_money, status, material, specification, price,start_time,end_time,this);
            modify.Show();
            #endregion
        }

        private void button1_Click(object sender, EventArgs e)
        {
            add_material add_form = new add_material();
            add_form.Show();
        }

        private void add_button_Click(object sender, EventArgs e)
        {
            string key = "add";
            order_modify add_form = new order_modify(key,this);
            add_form.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Refresh_order_LV();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string id = this.main_order_listView.FocusedItem.SubItems[0].Text;
            string sql = "delete from t_order where id=" + id + "";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");

            }
            else
            {
                MessageBox.Show("删除失败！");

            }
            db.close();
            Refresh_order_LV();
        }
#endregion

        #region 库存材料
        public void Refresh_warehouse_material_LV()
        {
            warehouse_m_listview.Clear();
            this.warehouse_m_listview.Columns.Clear();
            this.warehouse_m_listview.Columns.Add("ID", 0, HorizontalAlignment.Left);

            this.warehouse_m_listview.Columns.Add("品种", 85, HorizontalAlignment.Left);
            this.warehouse_m_listview.Columns.Add("重量", 85, HorizontalAlignment.Left);
            this.warehouse_m_listview.Columns.Add("单价", 85, HorizontalAlignment.Left);
            string sql = "select * from T_WH_material";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["Species"].ToString());
                li.SubItems.Add(reader["Weight"].ToString());
                li.SubItems.Add(reader["Price"].ToString());
                warehouse_m_listview.Items.Add(li);
            }
            db.close();
        }
        #endregion

        #region 库存成品
        public void Refresh_warehouse_product_LV()
        {
            warehouse_p_listview.Clear();
            this.warehouse_p_listview.Columns.Clear();
            this.warehouse_p_listview.Columns.Add("ID", 0, HorizontalAlignment.Left);

            this.warehouse_p_listview.Columns.Add("品种", 85, HorizontalAlignment.Left);
            this.warehouse_p_listview.Columns.Add("材质", 85, HorizontalAlignment.Left);
            this.warehouse_p_listview.Columns.Add("规格", 85, HorizontalAlignment.Left);
            this.warehouse_p_listview.Columns.Add("重量", 75, HorizontalAlignment.Left);
            this.warehouse_p_listview.Columns.Add("单价", 75, HorizontalAlignment.Left);
            string sql = "select * from T_WH_product";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["Type"].ToString());
                li.SubItems.Add(reader["Material"].ToString());
                li.SubItems.Add(reader["Specification"].ToString());
                li.SubItems.Add(reader["Weight"].ToString());
                li.SubItems.Add(reader["Price"].ToString());
                warehouse_p_listview.Items.Add(li);
            }
            db.close();
        }
        #endregion

        #region 材料种类
        public void Refresh_material_species_LV()
        {
            material_listview.Clear();
            this.material_listview.Columns.Clear();

            this.material_listview.Columns.Add("材料种类", 160, HorizontalAlignment.Left);
            string sql = "select NAME from T_material";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["NAME"].ToString();
                material_listview.Items.Add(li);
            }
            db.close();
        }
        #endregion

        #region 仓库信息处理
        private void button1_Click_1(object sender, EventArgs e)
        {
            WH_add_product add_form = new WH_add_product(this);
            add_form.Show();
        }

        private void add_meterial_Click(object sender, EventArgs e)
        {
            WH_add_material add_form = new WH_add_material(this);
            add_form.Show();
        }

        private void 入库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string material = this.warehouse_p_listview.FocusedItem.SubItems[2].Text;
            string name = this.warehouse_p_listview.FocusedItem.SubItems[1].Text;
            string sum = material + name;
            string weight = this.warehouse_p_listview.FocusedItem.SubItems[4].Text;
            string id = this.warehouse_p_listview.FocusedItem.SubItems[0].Text;
            string price = this.warehouse_p_listview.FocusedItem.SubItems[5].Text;
            intoWH_product newForm = new intoWH_product(weight,id,price,sum,this);
            newForm.ShowDialog();
        }
        //取得修改过的返回值，平均价值和
        public void recive(string price,string weight)
        {
            this.warehouse_p_listview.FocusedItem.SubItems[5].Text=price;
            this.warehouse_p_listview.FocusedItem.SubItems[4].Text = weight;
        }

        private void 出库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string material = this.warehouse_p_listview.FocusedItem.SubItems[2].Text;
            string name = this.warehouse_p_listview.FocusedItem.SubItems[1].Text;
            string sum = material + name;
            string weight = this.warehouse_p_listview.FocusedItem.SubItems[4].Text;
            string id = this.warehouse_p_listview.FocusedItem.SubItems[0].Text;
            string price = this.warehouse_p_listview.FocusedItem.SubItems[5].Text;
            outWH_product newForm = new outWH_product(weight, id, price, sum, this);
            newForm.ShowDialog();
        }
        public void clearout()
        {
           Refresh_warehouse_product_LV();
        }

        private void 出库原料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string id = this.warehouse_m_listview.FocusedItem.SubItems[0].Text;
            string species = this.warehouse_m_listview.FocusedItem.SubItems[1].Text;
            string weight = this.warehouse_m_listview.FocusedItem.SubItems[2].Text;
            string price = this.warehouse_m_listview.FocusedItem.SubItems[3].Text;
            outWH_material form = new outWH_material(id, species, weight, price, this);
            form.Show();
        }

        private void 入库原料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string id = this.warehouse_m_listview.FocusedItem.SubItems[0].Text;
            string species = this.warehouse_m_listview.FocusedItem.SubItems[1].Text;
            string weight = this.warehouse_m_listview.FocusedItem.SubItems[2].Text;
            string price = this.warehouse_m_listview.FocusedItem.SubItems[3].Text;
            intoWH_material form=new intoWH_material(id, species, weight, price, this);
            form.Show();
        }
        #endregion

        #region 第三页生产计划管理
        public void Refresh_plain_LV()
        {
            year_cb.Items.Clear();
            string today = System.DateTime.Now.ToString();
            today = today.Substring(0, 4);
            int t = Convert.ToInt32(today);
            for (int i = 0; i < 4; i++)
            {
                year_cb.Items.Add(t + 2 - i);
            }

            plain_lv.Clear();
            this.plain_lv.Columns.Clear();
            this.plain_lv.Columns.Add("日期", 90, HorizontalAlignment.Left);

            this.plain_lv.Columns.Add("生产计划", 820, HorizontalAlignment.Left);

            string sql = "select * from T_plain";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["Plain"].ToString());
                plain_lv.Items.Add(li);
            }
            db.close();
        }
        #endregion

        #region 查询生产计划
        private void button1_Click_2(object sender, EventArgs e)
        {
            if (this.year_cb.SelectedItem != null&&this.mouth_cb.SelectedItem!=null)
            {
                plain_lv.Items.Clear();
                string year = this.year_cb.SelectedItem.ToString();
                string mouth = this.mouth_cb.SelectedItem.ToString();
                string ym = year + mouth;
                string sql = "select * from T_plain where ID like '" + ym + "%'";
                DBhelp db = new DBhelp();
                SqlDataReader reader = db.query(sql);


                while (reader.Read())
                {
                    ListViewItem li = new ListViewItem();
                    li.SubItems.Clear();
                    li.SubItems[0].Text = reader["ID"].ToString();
                    li.SubItems.Add(reader["Plain"].ToString());
                
                    plain_lv.Items.Add(li);
                }
                db.close();
            }
            else
            { 
                MessageBox.Show("请选择年月！"); 
            }
        }
        #endregion

        #region 生产计划增改
        private void button3_Click(object sender, EventArgs e)
        {
            add_plain form = new add_plain(this);
            form.Show();
        }

        private void 修改ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string id = plain_lv.FocusedItem.SubItems[0].Text;
            string plain = plain_lv.FocusedItem.SubItems[1].Text;
            add_plain form = new add_plain(id,plain,this);
            form.Show();
        }
        #endregion

        #region 生产管理记录
        public void Refresh_ingot_LV()
        {
            ingot_lv.Clear();
            ingot_lv.Columns.Clear(); 
            ingot_lv.Columns.Add("时间", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("炉号", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("材质", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("重量", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("数量", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("耗材", 70, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("情况说明", 270, HorizontalAlignment.Left);
            ingot_lv.Columns.Add("interID", 0, HorizontalAlignment.Left);
            string sql = "select count(*) from T_ingot";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            int count = 0;
            while (reader.Read())
            {
                count = (int)reader.GetValue(0);
            }
            db.close();

            sql = "select * from T_ingot";
            db = new DBhelp();
            reader = db.query(sql);
            string[] ID = new string[count];
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["ID"].ToString();
                li.SubItems.Add(reader["PotNum"].ToString());
                li.SubItems.Add(reader["Material"].ToString());
                li.SubItems.Add(reader["Weight"].ToString());
                li.SubItems.Add(reader["Num"].ToString());
                li.SubItems.Add(reader["Cost"].ToString());
                li.SubItems.Add(reader["Note"].ToString());
                li.SubItems.Add(reader["InterID"].ToString());
                ingot_lv.Items.Add(li);
            }
            db.close();
            //下面就是把要添加的耗材加入钢锭表
        }
#endregion

        #region 钢锭处理_初始化
        public void Refresh_ingot_process_LV(string type)
        {
            string sql = "";
            if (type.Equals("n"))
            {
                sql = "select * from T_ingot_process";
            }
            else
            {
                sql = "select * from T_ingot_process where time like '" + type + "%'"; ;
            }
            ingot_process_lv.Clear();
            ingot_process_lv.Columns.Clear();
            ingot_process_lv.Columns.Add("时间", 80, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("炉号", 85, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("材质", 85, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("重量", 85, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("加工目标", 130, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("加工情况", 130, HorizontalAlignment.Left);
            ingot_process_lv.Columns.Add("interID",0, HorizontalAlignment.Left);
            
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["time"].ToString();
                li.SubItems.Add(reader["potnum"].ToString());
                li.SubItems.Add(reader["material"].ToString());
                li.SubItems.Add(reader["weight"].ToString());
                li.SubItems.Add(reader["target"].ToString());
                li.SubItems.Add(reader["situation"].ToString());
                li.SubItems.Add(reader["InterID"].ToString());
                ingot_process_lv.Items.Add(li);
            }
            db.close();
        }
        #endregion

        #region 计划_删除
        private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string id = plain_lv.FocusedItem.SubItems[5].Text;
            string sql = "delete from T_plain where InterID='" + id + "'";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();
            Refresh_plain_LV();
        }
        #endregion

        #region 查询_钢锭
        private void button4_Click(object sender, EventArgs e)
        {
 
       
            if (this.produce_year_cb.SelectedItem != null && this.produce_mouth_cb.SelectedItem != null)
            {
                string sql = "select count(*) from T_ingot";
                DBhelp db = new DBhelp();
                SqlDataReader reader = db.query(sql);
                int count = 0;
                while (reader.Read())
                {
                    count = (int)reader.GetValue(0);
                }
                db.close();
                
                ingot_lv.Items.Clear();
                string year = this.produce_year_cb.SelectedItem.ToString();
                string mouth = this.produce_mouth_cb.SelectedItem.ToString();
                string ym = year + mouth;
                sql = "select * from T_ingot where ID like '" + ym + "%'";
                db = new DBhelp();
                reader = db.query(sql);
                string[] ID = new string[count];
                while (reader.Read())
                {
                    ListViewItem li = new ListViewItem();
                    li.SubItems.Clear();
                    li.SubItems[0].Text = reader["ID"].ToString();
                    li.SubItems.Add(reader["PotNum"].ToString());
                    li.SubItems.Add(reader["Material"].ToString());
                    li.SubItems.Add(reader["Weight"].ToString());
                    li.SubItems.Add(reader["Num"].ToString());
                    li.SubItems.Add(reader["Cost"].ToString());
                    li.SubItems.Add(reader["Note"].ToString());
                    li.SubItems.Add(reader["InterID"].ToString());
                    ingot_lv.Items.Add(li);
                }
                db.close();

                //下面就是把要添加的耗材加入钢锭表
                
                
             
  
            }
            else
            {
                MessageBox.Show("请选择年月！");
            }
        }
        #endregion

        #region 质量管理_初始化
        //下面是质量管理
         public void Refresh_Quality_LV()
        {
            Quality_lv.Clear();
            this.Quality_lv.Columns.Clear();
            this.Quality_lv.Columns.Add("interID", 0, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("类型", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("日期", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("炉号", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("材质/规格", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("重量", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("情况", 815, HorizontalAlignment.Left);
            string sql = "select * from T_Quality";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["InterID"].ToString();
                li.SubItems.Add(reader["Type"].ToString());
                li.SubItems.Add(reader["ID"].ToString());
                li.SubItems.Add(reader["Potnum"].ToString());
                li.SubItems.Add(reader["Material"].ToString());
                li.SubItems.Add(reader["Weight"].ToString());
                li.SubItems.Add(reader["Note"].ToString());
                Quality_lv.Items.Add(li);
            }
            db.close();
        }
#endregion

        #region 黑板管理_初始化
         public void Refresh_black_process_LV(string type)
         {
             string sql = "";
             if (type.Equals("n"))
             {
                 sql = "select * from T_black_process";
             }
             else
             {
                 sql = "select * from T_black_process where time like '" + type + "%'"; ;
             }


             black_process_lv.Clear();
             this.black_process_lv.Columns.Clear();
             this.black_process_lv.Columns.Add("时间", 80, HorizontalAlignment.Left);
             this.black_process_lv.Columns.Add("材质", 85, HorizontalAlignment.Left);
             this.black_process_lv.Columns.Add("规则", 85, HorizontalAlignment.Left);
             this.black_process_lv.Columns.Add("加工目标", 85, HorizontalAlignment.Left);
             this.black_process_lv.Columns.Add("加工情况", 85, HorizontalAlignment.Left);
             this.black_process_lv.Columns.Add("interID", 0, HorizontalAlignment.Left);
            
             DBhelp db = new DBhelp();
             SqlDataReader reader = db.query(sql);
             while (reader.Read())
             {
                 ListViewItem li = new ListViewItem();
                 li.SubItems.Clear();
                 li.SubItems[0].Text = reader["time"].ToString();
                 li.SubItems.Add(reader["material"].ToString());
                 li.SubItems.Add(reader["black_rule"].ToString());
                 li.SubItems.Add(reader["target"].ToString());
                 li.SubItems.Add(reader["situation"].ToString());
                 li.SubItems.Add(reader["interID"].ToString());
         
                 black_process_lv.Items.Add(li);
             }
             db.close();
         }
#endregion

        #region 白板管理_初始化
         public void Refresh_white_process_LV(string type)
         {

             string sql = "";
             if (type.Equals("n"))
             {
                 sql = "select * from T_white_process";
             }
             else
             {
                 sql = "select * from T_white_process where time like '" + type + "%'"; ;
             }
             white_process_lv.Clear();
             this.white_process_lv.Columns.Clear();
             this.white_process_lv.Columns.Add("时间", 80, HorizontalAlignment.Left);
             this.white_process_lv.Columns.Add("材质", 85, HorizontalAlignment.Left);
             this.white_process_lv.Columns.Add("规格", 85, HorizontalAlignment.Left);
             this.white_process_lv.Columns.Add("加工情况", 85, HorizontalAlignment.Left);
             this.white_process_lv.Columns.Add("interID", 0, HorizontalAlignment.Left);
            
             DBhelp db = new DBhelp();
             SqlDataReader reader = db.query(sql);
             while (reader.Read())
             {
                 ListViewItem li = new ListViewItem();
                 li.SubItems.Clear();
                 li.SubItems[0].Text = reader["time"].ToString();
                 li.SubItems.Add(reader["material"].ToString());
                 li.SubItems.Add(reader["specification"].ToString());
                 li.SubItems.Add(reader["situation"].ToString());
                 li.SubItems.Add(reader["interID"].ToString());

                 white_process_lv.Items.Add(li);
             }
             db.close();
         }
#endregion

        #region 钢锭管理_添加
         private void button5_Click(object sender, EventArgs e)
        {
            add_ingot form = new add_ingot(this);
            form.Show();
        }
        #endregion

        #region 钢锭管理_修改
         private void 修改ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            string id = ingot_lv.FocusedItem.SubItems[0].Text;
            string potnum = ingot_lv.FocusedItem.SubItems[1].Text;
            string material= ingot_lv.FocusedItem.SubItems[2].Text;
            string weight= ingot_lv.FocusedItem.SubItems[3].Text;
            string num= ingot_lv.FocusedItem.SubItems[4].Text;
            string cost = ingot_lv.FocusedItem.SubItems[5].Text;
            string note = ingot_lv.FocusedItem.SubItems[6].Text;
            string interid = ingot_lv.FocusedItem.SubItems[7].Text;
            add_ingot form = new add_ingot(id, potnum,cost, weight,num,note,material,interid, this);
            form.Show();
        }
#endregion

        #region 钢锭管理_删除
         private void 删除ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            string id = ingot_lv.FocusedItem.SubItems[0].Text;
            string sql = "delete from T_ingot where ID='" + id + "'";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();
            Refresh_ingot_LV();
        }
#endregion

         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
         #region 钢锭处理_修改
         private void 修改ToolStripMenuItem3_Click(object sender, EventArgs e)
        {

            string id = ingot_process_lv.FocusedItem.SubItems[0].Text;
            string potnum = ingot_process_lv.FocusedItem.SubItems[1].Text;
            string material = ingot_process_lv.FocusedItem.SubItems[2].Text;
            string weight = ingot_process_lv.FocusedItem.SubItems[3].Text;
            string target = ingot_process_lv.FocusedItem.SubItems[4].Text;
            string situation = ingot_process_lv.FocusedItem.SubItems[5].Text;
            string interid = ingot_process_lv.FocusedItem.SubItems[6].Text;
            add_ingot_process form = new add_ingot_process(interid, id, potnum, material, weight, target, situation, this);
            form.Show();
        }
         #endregion

         #region 钢锭处理_删除
         private void 删除ToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            string id = ingot_process_lv.FocusedItem.SubItems[6].Text;
            string sql = "delete from T_ingot_process where interID='" + id + "'";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();
            Refresh_ingot_process_LV("n");
        }
#endregion

         #region 钢锭处理_添加
         private void add_steel_Click_1(object sender, EventArgs e)
        {
            add_ingot_process form1 = new add_ingot_process(this);
            form1.Show();
        }
#endregion

         #region 质量管理_添加
         private void add_bt_Click(object sender, EventArgs e)
        {
            add_qualitymanager form1 = new add_qualitymanager(this);
            form1.Show();
        }
#endregion

         #region 质量管理_修改
         private void 修改ToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            string interid = Quality_lv.FocusedItem.SubItems[0].Text;
            string type = Quality_lv.FocusedItem.SubItems[1].Text;
            string date = Quality_lv.FocusedItem.SubItems[2].Text;
            string potnum = Quality_lv.FocusedItem.SubItems[3].Text;
            string material = Quality_lv.FocusedItem.SubItems[4].Text;
            string weight = Quality_lv.FocusedItem.SubItems[5].Text;
            string note = Quality_lv.FocusedItem.SubItems[6].Text;
            add_qualitymanager form = new add_qualitymanager(interid,type,date,potnum,material,weight,note, this);
            form.Show();
        }
#endregion

         #region 质量管理_删除
         private void 删除ToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            string id = Quality_lv.FocusedItem.SubItems[0].Text;
            string sql = "delete from T_Quality where InterID='" + id + "'";
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();
            Refresh_Quality_LV();
        }
#endregion

         #region 质量管理_初始化
         private void button5_Click_1(object sender, EventArgs e)
        {
            string ym = this.quality_lv_year_cb.SelectedItem.ToString() + this.quality_lv_month_cb.SelectedItem.ToString();
            Quality_lv.Clear();
            this.Quality_lv.Columns.Clear();
            this.Quality_lv.Columns.Add("interID", 0, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("类型", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("日期", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("炉号", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("材质/规格", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("重量", 85, HorizontalAlignment.Left);
            this.Quality_lv.Columns.Add("情况", 815, HorizontalAlignment.Left);
            string sql = "select * from T_Quality where ID like '" + ym + "%'";
            DBhelp db = new DBhelp();
            SqlDataReader reader = db.query(sql);
            while (reader.Read())
            {
                ListViewItem li = new ListViewItem();
                li.SubItems.Clear();
                li.SubItems[0].Text = reader["InterID"].ToString();
                li.SubItems.Add(reader["Type"].ToString());
                li.SubItems.Add(reader["ID"].ToString());
                li.SubItems.Add(reader["Potnum"].ToString());
                li.SubItems.Add(reader["Material"].ToString());
                li.SubItems.Add(reader["Weight"].ToString());
                li.SubItems.Add(reader["Note"].ToString());
                Quality_lv.Items.Add(li);
            }
            db.close();
        }
#endregion

         #region 黑板处理_修改
         private void 修改ToolStripMenuItem5_Click(object sender, EventArgs e)
        {
           
            string time = black_process_lv.FocusedItem.SubItems[0].Text;
            string material = black_process_lv.FocusedItem.SubItems[1].Text;
            string rule = black_process_lv.FocusedItem.SubItems[2].Text;
            string target = black_process_lv.FocusedItem.SubItems[3].Text;
            string situation = black_process_lv.FocusedItem.SubItems[4].Text;
            string interID = black_process_lv.FocusedItem.SubItems[5].Text;
            black_process form = new black_process(interID,time,material,rule,target,situation,this);
            form.Show();
        }
#endregion

         #region 黑板处理_添加
         private void black_process_bt_Click(object sender, EventArgs e)
        {
            black_process form = new black_process( this);
            form.Show();
        }
#endregion

         #region 白板处理_添加
         private void white_process_bt_Click(object sender, EventArgs e)
        {
            white_process form = new white_process(this);
            form.Show();
        }
#endregion

         #region 白板处理_修改
         private void 修改ToolStripMenuItem6_Click(object sender, EventArgs e)
        {
            string time = white_process_lv.FocusedItem.SubItems[0].Text;
            string material = white_process_lv.FocusedItem.SubItems[1].Text;
            
            string specification = white_process_lv.FocusedItem.SubItems[2].Text;
            string situation = white_process_lv.FocusedItem.SubItems[3].Text;
            string interID = white_process_lv.FocusedItem.SubItems[4].Text;
            white_process form = new white_process(interID, time, material,specification, situation, this);
            form.Show();
        }
#endregion

         #region 黑板处理_删除
         private void 删除ToolStripMenuItem5_Click(object sender, EventArgs e)
        {
            string id = black_process_lv.FocusedItem.SubItems[5].Text;
            string sql = "delete from T_black_process where InterID='" + id + "'";
           
            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();
            
            Refresh_black_process_LV("n");
        }
#endregion

         #region 白板处理_删除
         private void 删除ToolStripMenuItem6_Click(object sender, EventArgs e)
        {
            string id = white_process_lv.FocusedItem.SubItems[4].Text;
            string sql = "delete from T_white_process where InterID='" + id + "'";

            DBhelp db = new DBhelp();
            int rs = db.update(sql);
            if (rs == 1)
            {
                MessageBox.Show("删除成功！");
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
            db.close();

            Refresh_white_process_LV("n");
        }
#endregion

         private void query_process_bt_Click(object sender, EventArgs e)
         {
             string time = this.year_process.SelectedItem.ToString()+this.month_process.SelectedItem.ToString();

             string type=Type_cb.SelectedItem.ToString();

             if (type.Equals("钢锭查询"))
             {
                 Refresh_ingot_process_LV(time);    
             }
             else if (type.Equals("黑板查询"))
             {
                 Refresh_black_process_LV(time);
             }
             else if (type.Equals("白板查询"))
             {
                 Refresh_white_process_LV(time);
             }
         }


    }
}
